<?=$this->load->view('include_header',null)?>
	<div id="top-panel">
		<div id="panel">
			<ul>
				<li class="current"><a href="<?=site_url('archive/idcard/'.$id)?>" class="report"><?=(empty($id))?"录入新":"编辑"?>客户基本信息</a></li>
				
			</ul>
		</div>
	</div>
	<div id="wrapper">
		<div id="content">
			<div id="box">
				<form id="form">
				<fieldset>
				<legend>行程单信息</legend>
					<div id="bl">
					</div>
				
					<input type="button" id="button1" value="增加一个安排" />
					<input type="button" id="button2" value="保存行程单" />
				</fieldset>
				</form>
				
				<form id="subform" method="POST" action="<?=site_url('order/itinery_update/'.$cateid)?>">
				<input type="hidden" name="contents" id="contents" value="<?=@$info->contents?>" />
				<input type="hidden" name="id" value="<?=$id?>" />
				</form>
			</div>
		</div>
		
		<?=$this->load->view('include_sidebar',array('id'=>$id,'forms'=>$forms))?>
	</div>

	<script type="text/javascript">

	$(document).ready(function(){
		$("#button1").click( function() {
			writeTag(true);
			
			$("fieldset:.jobline:last").find("[type='button']").click( function() {
				$(this).parent().remove();
			});
            
            resize_parent_iframe();  
		});

		$("#button2").click(function() {
			var arr=[];
			$("fieldset:.jobline").each(function(){
				//alert($(this).html());
				arr.push( {begin_date:$(this).find("#begin_date").val(), end_date:$(this).find("#end_date").val(), routing:$(this).find("#routing").val(), transport:$(this).find("#transport").val() });
			});
			//alert(JSON.stringify(arr));
			$("#contents").val(JSON.stringify(arr));
			if ($("#contents").val()=="") {
				alert("您没有录入行程信息");
				return false;
			}
			$("#subform").submit(); 
		});
		
		var inits = <?=empty($info->contents)?"undefined":@$info->contents?>;
		if(inits==undefined){
			writeTag(false);
		}else{
			$.each( inits, function(i, n){
				//alert( "Name: " + i + ", Value: " + n );
				writeTag(true);
				$("fieldset:.jobline:last").find("[type='button']").click( function() {
					$(this).parent().remove();
				});
				$("fieldset:.jobline:last").find("#begin_date").val(n.begin_date);
				$("fieldset:.jobline:last").find("#end_date").val(n.end_date);
				$("fieldset:.jobline:last").find("#routing").val(n.routing);
				$("fieldset:.jobline:last").find("#transport").val(n.transport);
			}); 
		}
         
	});
	
	function writeTag( removeable ){
		var str="";
		str+='<fieldset class="jobline">'
		str+='<legend>安排</legend>'
		str+='<label>开始日期:</label><input type="text" id="begin_date" name="begin_date" /> <br />'
		str+='<label>结束日期:</label><input type="text" id="end_date" name="end_date" /> <br />'
		str+='<label>行程说明:</label><input type="text" id="routing" size="40" name="routing" /> <br />'
		str+='<label>交通方式:</label><input type="text" id="transport" size="40" name="transport" /> <br />'
		if (removeable) str+='<input type="button" value=" 移除 " /> <br />';
		str+='</fieldset>';
		
		$("#bl").append(str);

		/*		
		var bdate = 'begin_date'+col
		var rout = 'routing'+col
		var trans = 'transport'+col
		$("#form").validate({
			rules: {
				bdate:{
				  required:true
				},
				rout:{
				  required:true,
				  minlength:3
				},
				trans:{
				  required:true,
				  minlength:3
				}
			}
		});

		$( "[name='begin_date"+col+"']" ).datepicker({
			changeMonth: true,
			changeYear: true,
			showOn: "both",
			buttonImage: "images/calendar.gif",
			buttonImageOnly: true
		});
		$( "[name='end_date"+col+"']" ).datepicker({
			changeMonth: true,
			changeYear: true,
			showOn: "both",
			buttonImage: "images/calendar.gif",
			buttonImageOnly: true
		});
		col ++;
		*/
	}
	</script>

<?=$this->load->view('include_footer',null)?>
